package com.jianzh5.common;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Random;

/**
 * Created by jianzh5 on 2015/5/13.
 * Description : JSP环境探针
 * @version : 1.0
 * @Date : 2015-05-13
 */
public class EnvParams {
    public long timeUse = 0;
    public Hashtable<String,String> htParams = new Hashtable<String,String>();
    private Hashtable<String, String> htShowMsg = new Hashtable<String, String>();

    public void setHashTable(){
        Properties me = System.getProperties();
        Enumeration<String> em = (Enumeration<String>) me.propertyNames();
        while(em.hasMoreElements()){
            String strKey = em.nextElement();
            String strValue = (String) me.get(strKey);
            htParams.put(strKey,strValue);
        }
    }

    public void getHashTable(String strQuery){
        Enumeration<String> em = htParams.keys();
        while(em.hasMoreElements()){
            String strKey = em.nextElement();
            String strValue = new String();
            if (strKey.indexOf(strQuery, 0) >= 0) {
                strValue = htParams.get(strKey);
                htShowMsg.put(strKey, strValue);
            }
        }
    }

    public String queryHashtable(String strKey) {
        strKey = (String) htParams.get(strKey);
        return strKey;
    }

    public long test_int() {
        long timeStart = System.currentTimeMillis();
        int i = 0;
        while (i < 3000000)
            i++;
        long timeEnd = System.currentTimeMillis();
        long timeUse = timeEnd - timeStart;
        return timeUse;
    }

    public long test_sqrt() {
        long timeStart = System.currentTimeMillis();
        int i = 0;
        double db = (double) new Random().nextInt(1000);
        while (i < 200000) {
            db = Math.sqrt(db);
            i++;
        }
        long timeEnd = System.currentTimeMillis();
        long timeUse = timeEnd - timeStart;
        return timeUse;
    }

    public Hashtable<String, String> getHtShowMsg() {
        return htShowMsg;
    }

}
